﻿using System.Collections.Generic;

namespace IceDog.DNF.Program.Dapper.Mapping
{
    public class ColumnMap
    {
        private readonly Dictionary<string, string> _forward = new Dictionary<string, string>();
        private readonly Dictionary<string, string> _reverse = new Dictionary<string, string>();

        public void Add(string fieldName, string columnName)
        {
            _forward.Add(fieldName, columnName);
            _reverse.Add(columnName, fieldName);
        }

        public string this[string index]
        {
            get
            {
                // Check for a custom column map.
                if (_forward.ContainsKey(index))
                    return _forward[index];
                if (_reverse.ContainsKey(index))
                    return _reverse[index];

                // If no custom mapping exists, return the value passed in.
                return index;
            }
        }
    }
}
